/**
 * 加载商品列表数据
 */
function load() {
    $.ajax({
        type: 'get',
        url: 'http://www.xiongmaoyouxuan.com/api/tab/1',
        data: {
            start: 0
        },
        success: function (result) {
            let response = result
            if (response.code == 200) {
                let productList = response.data.items.list
                // console.log(productList);
                Panda(productList)
            }
        }
    })
}

function Panda(productList) {
    let data = {
        productList: productList.splice(0,16)
    }
    let htmlStr = template('productList', data)
    $('.cie_a1').html(htmlStr)
}

/**
 * 加载添加到详情页
 */

function addCart(id) {
    
    console.log(id);
    let cartListStr = localStorage.getItem('CARTLIST')
    let cartList = JSON.parse(cartListStr) || []
    cartList.unshift(id)
    localStorage.setItem('CARTLIST', JSON.stringify(cartList))
    location.href = './cart.html'

}
// 滚动条事件
onscroll = function() {
	//滚动距离兼容写法
	var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
	//判断
	if (scrollTop >= 400) {
		$('.D-top').css('display', 'block')
	} else {
		$('.D-top').css('display', 'none')
	}
}

//回到顶部
function onBack() {
	var scrollTo = document.documentElement.scrollTop || document.body.scrollTop;
	let timer = setInterval(() => {
		if (scrollTo > 10) {
			scrollTo -= 1
			document.documentElement.scrollTop = scrollTo;
		} else {
			clearInterval(timer)
		}
	}, 1)

}
onscroll()
load()
//点击查看更多
let cumulative = 0
//点击查看更多
function onView() {
	cumulative += 20
	let start = cumulative
	$.ajax({
		type: 'get',
		url: 'http://www.xiongmaoyouxuan.com/api/tab/1/feeds',
		data: {
			start,
			sort: 0
		},
		success: function(Accumulate) {
			if (Accumulate.code == 200) {
				rendering(Accumulate)
			}
		},

	})
}


//更多商品渲染
function rendering(i) {

	let srt = i.data.list
	let data = {
		cert: srt.splice(0, 16)
	}

	let htmlStr3 = template('prot', data)
	console.log(htmlStr3)
	$('.cie_a1').append(htmlStr3)
}


function supplemental2() {
    location.href = './Top-jump.html'
}
function supplemental3() {
    location.href = './TopSwitch-two.html'
}
function supplemental4() {
    location.href = './TopSwitch-t.html'
}